﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using SpeechToText.STT;
using SpeechToText.TESTS;

namespace SpeechToText
{
    public partial class Form1 : Form
    {
        private VoiceDecoder VD = null;

        public Form1()
        {
            InitializeComponent();
        }

        private void OnVoice(DecodedSpeech DS)
        {
            tSpeech.Clear();

            string[] Text = new string[5];

            Text[0] = "Время: " + DS.DateTime.ToLongTimeString();
            Text[1] = "Достоверность: " + DS.TrueIndex;
            Text[2] = "Язык: " + DS.Language;
            Text[3] = "";
            Text[4] = "Текст: \n" + DS.Text;

            tSpeech.Lines = Text;

        }

        private void bStart_Click(object sender, EventArgs e)
        {
            if (VD == null)     
            {
                MessageBox.Show("Задайте параметры");
                return;
            }

            if (VD.isWorked)
            {
                VD.Stop();
                bStart.Text = "Старт";
            }
            else
            {
                VD.Start();
                bStart.Text = "Стоп";
            }
                

        }

        private void bSettings_Click(object sender, EventArgs e)
        {
            if (VD != null)
            {
                VD.Dispose();
            }

            int S = 0;
            double V = 0;

            try
            {
                S = Convert.ToInt32(tSilentTime.Text);
                V = Convert.ToDouble(tVolume.Text);
            }
            catch
            {
                MessageBox.Show("Значения заданы не верно");
            }

            VD = new VoiceDecoder(V, S, this, Languages.Ru);
            VD.OnGetSpeech += OnVoice;           
        }

        ~Form1()
        {
            if (VD != null) VD.Dispose();
        }

        private void bTests_Click(object sender, EventArgs e)
        {
            MyTest.test_WavResourse_Join();
            MyTest.test_WavResourse_isNoisy();
            MyTest.test_FlacResouce();
            MyTest.test_Microphone(this);
        }
    }
}
